package com.github.jdk8Date;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAdjusters;
import java.util.Locale;

public class DateParseFormatExample {

    public static void main(String[] args) {

        //Format examples
//        LocalDate date = LocalDate.now();
//        //default format
//        System.out.println("Default format of LocalDate= "+date);
//        //specific format
//        System.out.println(date.format(DateTimeFormatter.ofPattern("d::MMM::uuuu")));
//        System.out.println(date.format(DateTimeFormatter.ofPattern("uuuu/MM/dd")));
//        System.out.println(date.format(DateTimeFormatter.BASIC_ISO_DATE));
//
//        LocalDateTime dateTime = LocalDateTime.now();
//        //default format
//        System.out.println("Default format of LocalDateTime= "+dateTime);
//        //specific format
//        System.out.println(dateTime.format(DateTimeFormatter.ofPattern("d::MMM::uuuu HH::mm::ss")));
//        System.out.println(dateTime.format(DateTimeFormatter.BASIC_ISO_DATE));
//
//        Instant timestamp = Instant.now();
//        //default format
//        System.out.println("Default format of Instant= "+timestamp);
//
//        //Parse examples
//        LocalDateTime dt = LocalDateTime.parse("27::十一月::2014 21::39::48", DateTimeFormatter.ofPattern("d::MMM::uuuu HH::mm::ss"));
//        System.out.println("Default format after parsing = "+dt);

        DateTimeFormatter dtf = new DateTimeFormatterBuilder().parseCaseInsensitive().appendPattern("dd_MMM_yy_HH_mm_ss_SSS").toFormatter(Locale.US);
        LocalDateTime localDateTime = LocalDateTime.parse("04_Apr_23_00_12_38_511", dtf);
        System.out.println(localDateTime);


        DateTimeFormatter dtf1 = new DateTimeFormatterBuilder().append(DateTimeFormatter.ofPattern("yyyyMM"))
                .parseDefaulting(ChronoField.DAY_OF_MONTH, 1)
                .toFormatter();

        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDate yyyyMM = LocalDate.parse(String.valueOf("202305"), dtf1);
        String startTime = LocalDateTime.of(yyyyMM, LocalTime.MIN).format(dateTimeFormatter);
        String endTime = LocalDateTime.of(yyyyMM,LocalTime.MAX).with(TemporalAdjusters.lastDayOfMonth()).format(dateTimeFormatter);
        System.out.println(startTime);
        System.out.println(endTime);

    }

}